Skip to content

Histogram storage format and bin count (D9): study, not for merge - #107

Draft
guijacquemet wants to merge 1 commit into
mainfrom
study/histogram-storage
Draft

guijacquemet wants to merge 1 commit into
mainfrom
study/histogram-storage

Conversation

@guijacquemet

Copy link
Copy Markdown
Contributor

Roadmap step D9: a measured benchmark, run before any Spec change. Study, not for merge. Nothing in src/ changes. Everything is in experiments/histogram_storage_study/; the report is README.md and the full tables are in results.md.

Question (owner): do we need 65,536 bins per uint16 channel in plane_histograms.csv, and is there a more efficient format?

Data. Four datasets, read on a shared 4-CPU machine, one job at a time, with 5 repeats:

  • PR #318's benchmark data: 76 synthetic uint16 planes;
  • CMU-1: uint8 RGB crops;
  • MorphoRelate HPMEC: uint16, with a used range of 13,402 or less plus one hot-pixel channel;
  • JUMP cpg0016: 90 full-range 16-bit planes, 32 of which reach 65,535.

What I compared.

  • (a) Today's dense CSV.
  • (b) Two exact sparse formats:
    • a CSV with one index:count;… cell per channel, in ADR 0004's grammar;
    • a long Parquet table.
  • (c) Exact trimmed arrays in npz and in zarr.
  • (d) Coarse histograms at 4,096 and 1,024 bins, with the min–max range and with the robust range.

Findings.

  • (b) and (c) give bit-identical results to today's CSV. I compared 6,515 numbers in every format with 0 differences. The numbers were every per-plane and pooled parameter of every method and scope, the image summaries and the intensity warnings.
  • (d) changes decisions on real 16-bit data:
    • 32 of 90 JUMP saturated fractions become blank, so the saturation check is skipped for them;
    • every fitted group is flagged approximate;
    • robust z-score scales are off by 6.7 % on JUMP at 4,096 bins and by up to 60 % on HPMEC;
    • one robust z-score fit is refused at 1,024 bins;
    • one new repeat_intensity_shift warning appears on JUMP at 1,024 bins.
  • The sparse CSV is much smaller and faster on partial-range data.
    • It is 16× to 44× smaller and 12× to 27× faster to write.
    • Preprocessing's staging cycle (one file per image, read back, then the final table) drops from 2.7 s to 0.11 s on PR #318's data.
    • On full-range 16-bit data (JUMP) it is only about 1.4× smaller and faster. Parquet does better there (3.8× smaller), but pyarrow is not a dependency of normalization, preprocessing or CellPatcher. It is only an optional extra in MorphoFeature (cli) and MorphoRelate (parquet).

Recommendation. Keep exact bins. Plan a schema v6 that replaces the bin columns with one sparse Histogram_Counts_<ID> cell per channel, in ADR 0004's grammar. The Spec impact and the open questions are in the README.


Generated by Claude Code

Measures the exact dense CSV (today), a sparse cell CSV (ADR 0004 grammar),
long Parquet, trimmed npz/zarr and 4,096/1,024-bin histograms on four
datasets; bit identity of the exact formats and the error and decisions of
the coarse bins. Nothing in src/ changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants